<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AlterQuizSheetsTable extends Migration
{
    const TABLE = 'quiz_sheets';
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable(static::TABLE)){
            Schema::table(static::TABLE, function (Blueprint $table) {
                $table->text('option_id')->change();
                $table->text('fill_content')->change();
            });
        }

        if (!Schema::hasColumn(static::TABLE, 'paper_id')) {
            Schema::table(static::TABLE, function (Blueprint $table) {
                $table->unsignedInteger('paper_id')->default(0);
            });
        }

        if (Schema::hasColumn(static::TABLE, 'user_agent')) {
            Schema::table(static::TABLE, function (Blueprint $table) {
                $table->dropColumn('user_agent');
            });
        }

        if (Schema::hasColumn(static::TABLE, 'user_id')) {
            Schema::table(static::TABLE, function (Blueprint $table) {
                $table->dropColumn('user_id');
            });
        }

        if (Schema::hasColumn(static::TABLE, 'start_at')) {
            Schema::table(static::TABLE, function (Blueprint $table) {
                $table->dropColumn('start_at');
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
